import api from '@/api'
import config from "@/config"
import http from "@/utils/request"
import tool from '@/utils/tool'
import handler from '@/utils/handler'

import jcxCodeEditor from "@/components/jcxCodeEditor/index.vue";
import jcxFormTable from "@/components/jcxFormTable/index.vue";
import jcxIconSelect from "@/components/jcxIconSelect/index.vue";
import jcxTableBar from "@/components/jcxTableBar/index.vue";
import jcxStatistic from "@/components/jcxStatistic/index.vue";
import jcxPage from "@/components/jcxPage/index.vue";

import * as elIcons from '@element-plus/icons-vue'
import * as jcxIcons from '@/assets/icons'

export default {
    install(app) {
        // 挂载全局对象
        app.config.globalProperties.$API = api;
        app.config.globalProperties.$CONFIG = config;
        app.config.globalProperties.$HTTP = http;
        app.config.globalProperties.$TOOL = tool;

        // 注册全局组件
        app.component('jcxCodeEditor', jcxCodeEditor);
        app.component('jcxFormTable', jcxFormTable);
        app.component('jcxIconSelect', jcxIconSelect);
        app.component('jcxTableBar', jcxTableBar);
        app.component('jcxStatistic', jcxStatistic);
        app.component('jcxPage', jcxPage);

        // 注册全局指令

        // 统一注册 el-icon 图标
        for (let icon in elIcons) {
            app.component(`ElIcon${icon}`, elIcons[icon])
        }
        // 统一注册 jcx-icon 图标
        for (let icon in jcxIcons) {
            app.component(`JcxIcon${icon}`, jcxIcons[icon])
        }

        // 关闭 async-validator 全局控制台警告
        window.ASYNC_VALIDATOR_NO_WARNING = 1

        // 全局代码错误捕捉
        app.config.errorHandler = handler
    }
}
